package com.project2.controller;


import com.project2.bean.CommonData;
import com.project2.bean.PageBo;
import com.project2.bean.ResultVo;

import com.project2.bean.po.MarketStorage;
import com.project2.service.AdminStorageService;

import javafx.application.Application;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping("admin/storage")
public class AdminStorageController {


    @Autowired
    AdminStorageService adminStorage;


    /*
    上传商品图片
     */
    @RequestMapping("create")
    public ResultVo create(@RequestParam("file") MultipartFile myFile) throws IOException {
        MarketStorage addpic = adminStorage.addpic(myFile);
        return ResultVo.ok(addpic);
    }

    /**
    *@Description:展现所有存储对象信息
    *@Param: 
    *@return:
    *@date: 2022/8/13
    *@Author: MH
    */

    @RequiresPermissions("admin:storage:list")
    @RequestMapping("list")
    public ResultVo showAllStorageInfo(String name,String key,PageBo pageBo) {
        CommonData<MarketStorage> allStorageInfo = adminStorage.showAllStorageInfo(name,key,pageBo);
        return ResultVo.ok(allStorageInfo);
    }

    /**
     *@Description:更改对象名称
     *@Param:
     *@return:
     *@date: 2022/8/13
     *@Author: MH
     */
    @RequiresPermissions("admin:storage:update")
    @RequestMapping("update")
    public ResultVo updateStorageName(@RequestBody MarketStorage marketStorage) {
        List<MarketStorage> updateStorageName = adminStorage.updateStorageName(marketStorage);
        return ResultVo.ok(updateStorageName);
    }

    /**
     *@Description:逻辑删除
     *@Param:
     *@return:
     *@date: 2022/8/13
     *@Author: MH
     */
    @RequiresPermissions("admin:storage:delete")
    @RequestMapping("delete")
    public ResultVo deleteStorage(@RequestBody MarketStorage marketStorage) {
        adminStorage.deleteStorage(marketStorage);
        return ResultVo.ok();
    }

}
